package com.example.mymusic.app;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;

import com.example.mymusic.utils.Music;

public class MyBluetoothConnStateReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d("TAG", "action: "+action);

        int bluetoothState = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, 0);
        Log.d("TAG", "bluetoothState: "+bluetoothState);
        if(action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED) ){
            switch (bluetoothState){
                case BluetoothAdapter.STATE_DISCONNECTED:
                    //蓝牙状态断开连接，暂停音乐
                    Music.pause();
                    break;
                case BluetoothAdapter.STATE_CONNECTED:
                    Music.start();
                    break;
            }
        }

    }
}
